<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="purchaserHqCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchaserHqCode', validatorRules.purchaserHqCode]" placeholder="请输入purchaserHqCode"></a-input>
        </a-form-item>
        <a-form-item label="ipoNo" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ipoNo', validatorRules.ipoNo]" placeholder="请输入ipoNo"></a-input>
        </a-form-item>
        <a-form-item label="supplierCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入supplierCode"></a-input>
        </a-form-item>
        <a-form-item label="woNo" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'woNo', validatorRules.woNo]" placeholder="请输入woNo"></a-input>
        </a-form-item>
        <a-form-item label="categoryCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categoryCode', validatorRules.categoryCode]" placeholder="请输入categoryCode"></a-input>
        </a-form-item>
        <a-form-item label="subclassCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclassCode', validatorRules.subclassCode]" placeholder="请输入subclassCode"></a-input>
        </a-form-item>
        <a-form-item label="materialsCode" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsCode', validatorRules.materialsCode]" placeholder="请输入materialsCode"></a-input>
        </a-form-item>
        <a-form-item label="materialsDescription" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsDescription', validatorRules.materialsDescription]" placeholder="请输入materialsDescription"></a-input>
        </a-form-item>
        <a-form-item label="materialsBatch" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsBatch', validatorRules.materialsBatch]" placeholder="请输入materialsBatch"></a-input>
        </a-form-item>
        <a-form-item label="productId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productId', validatorRules.productId]" placeholder="请输入productId"></a-input>
        </a-form-item>
        <a-form-item label="amount" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'amount', validatorRules.amount]" placeholder="请输入amount"></a-input>
        </a-form-item>
        <a-form-item label="unit" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'unit', validatorRules.unit]" placeholder="请输入unit"></a-input>
        </a-form-item>
        <a-form-item label="planStartDate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'planStartDate', validatorRules.planStartDate]" placeholder="请输入planStartDate"></a-input>
        </a-form-item>
        <a-form-item label="planFinishDate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'planFinishDate', validatorRules.planFinishDate]" placeholder="请输入planFinishDate"></a-input>
        </a-form-item>
        <a-form-item label="actualStartDate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'actualStartDate', validatorRules.actualStartDate]" placeholder="请输入actualStartDate"></a-input>
        </a-form-item>
        <a-form-item label="actualFinishDate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'actualFinishDate', validatorRules.actualFinishDate]" placeholder="请输入actualFinishDate"></a-input>
        </a-form-item>
        <a-form-item label="woStatus" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'woStatus', validatorRules.woStatus]" placeholder="请输入woStatus"></a-input>
        </a-form-item>
        <a-form-item label="processRouteNo" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processRouteNo', validatorRules.processRouteNo]" placeholder="请输入processRouteNo"></a-input>
        </a-form-item>
        <a-form-item label="dataSource" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSource', validatorRules.dataSource]" placeholder="请输入dataSource"></a-input>
        </a-form-item>
        <a-form-item label="dataSourceCreateTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSourceCreateTime', validatorRules.dataSourceCreateTime]" placeholder="请输入dataSourceCreateTime"></a-input>
        </a-form-item>
        <a-form-item label="isDeleted" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'isDeleted', validatorRules.isDeleted]" placeholder="请输入isDeleted"></a-input>
        </a-form-item>
        <a-form-item label="1：未读（默认状态）
0：成功；
" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入1：未读（默认状态）
0：成功；
"></a-input>
        </a-form-item>
        <a-form-item label="错误信息，接口同步返回消息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'message', validatorRules.message]" placeholder="请输入错误信息，接口同步返回消息"></a-input>
        </a-form-item>
        <a-form-item label="本条数据值新增/更新，0：新增，1：更新" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'status', validatorRules.status]" placeholder="请输入本条数据值新增/更新，0：新增，1：更新"></a-input>
        </a-form-item>
        <a-form-item label="全局交易流水号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'transno', validatorRules.transno]" placeholder="请输入全局交易流水号"></a-input>
        </a-form-item>
        <a-form-item label="workId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'workId', validatorRules.workId]" placeholder="请输入workId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="数据可见方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'openId', validatorRules.openId]" placeholder="请输入数据可见方"></a-input>
        </a-form-item>
        <a-form-item label="ownerId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ownerId', validatorRules.ownerId]" placeholder="请输入ownerId"></a-input>
        </a-form-item>
        <a-form-item label="产品型号规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'modelSpec', validatorRules.modelSpec]" placeholder="请输入产品型号规格"></a-input>
        </a-form-item>
        <a-form-item label="是否监造标志，0：否，1：是" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supervisionFlag', validatorRules.supervisionFlag]" placeholder="请输入是否监造标志，0：否，1：是"></a-input>
        </a-form-item>
        <a-form-item label="推送时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择推送时间" v-decorator="[ 'pushTime', validatorRules.pushTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZxjEipGdModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        purchaserHqCode:{rules: [{ required: true, message: '请输入purchaserHqCode!' }]},
        ipoNo:{rules: [{ required: true, message: '请输入ipoNo!' }]},
        supplierCode:{rules: [{ required: true, message: '请输入supplierCode!' }]},
        woNo:{rules: [{ required: true, message: '请输入woNo!' }]},
        categoryCode:{rules: [{ required: true, message: '请输入categoryCode!' }]},
        subclassCode:{rules: [{ required: true, message: '请输入subclassCode!' }]},
        materialsCode:{rules: [{ required: true, message: '请输入materialsCode!' }]},
        materialsDescription:{},
        materialsBatch:{},
        productId:{},
        amount:{rules: [{ required: true, message: '请输入amount!' }]},
        unit:{rules: [{ required: true, message: '请输入unit!' }]},
        planStartDate:{rules: [{ required: true, message: '请输入planStartDate!' }]},
        planFinishDate:{rules: [{ required: true, message: '请输入planFinishDate!' }]},
        actualStartDate:{},
        actualFinishDate:{},
        woStatus:{rules: [{ required: true, message: '请输入woStatus!' }]},
        processRouteNo:{},
        dataSource:{rules: [{ required: true, message: '请输入dataSource!' }]},
        dataSourceCreateTime:{rules: [{ required: true, message: '请输入dataSourceCreateTime!' }]},
        isDeleted:{rules: [{ required: true, message: '请输入isDeleted!' }]},
        ioflag:{rules: [{ required: true, message: '请输入1：未读（默认状态）0：成功；!' }]},
        message:{},
        status:{},
        transno:{},
        workId:{rules: [{ required: true, message: '请输入workId!' }]},
        openId:{rules: [{ required: true, message: '请输入数据可见方!' }]},
        ownerId:{rules: [{ required: true, message: '请输入ownerId!' }]},
        modelSpec:{},
        supervisionFlag:{},
        pushTime:{},
        },
        url: {
          add: "/zxEipGd/zxjEipGd/add",
          edit: "/zxEipGd/zxjEipGd/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'purchaserHqCode','ipoNo','supplierCode','woNo','categoryCode','subclassCode','materialsCode','materialsDescription','materialsBatch','productId','amount','unit','planStartDate','planFinishDate','actualStartDate','actualFinishDate','woStatus','processRouteNo','dataSource','dataSourceCreateTime','isDeleted','ioflag','message','status','transno','workId','openId','ownerId','modelSpec','supervisionFlag','pushTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'purchaserHqCode','ipoNo','supplierCode','woNo','categoryCode','subclassCode','materialsCode','materialsDescription','materialsBatch','productId','amount','unit','planStartDate','planFinishDate','actualStartDate','actualFinishDate','woStatus','processRouteNo','dataSource','dataSourceCreateTime','isDeleted','ioflag','message','status','transno','workId','openId','ownerId','modelSpec','supervisionFlag','pushTime'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>